package com.hkfrich.framework.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.hkfrich.common.utils.DateUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @ClassName MyMetaObjectHandler
 * @Desscription mybatis-plus 时间插入修改处理  自动添加 修改 时间
 * @Author _HeiShuai
 * @Date 2022/9/9 16:51
 * @Version 1.0
 **/
@Configuration
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", DateUtils.getNowDate(),metaObject);
        this.setFieldValByName("updateTime", DateUtils.getNowDate(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", DateUtils.getNowDate(),metaObject);
    }
}

